# Top-level Makefile for kpathsea-using programs.

# Package subdirectories, the library, and all subdirectories.
ESUBDIRS=@ESUBDIRS@

programs = web2c $(ESUBDIRS)
kpathsea_dir = kpathsea
all_dirs = $(programs) $(kpathsea_dir)

kpse_include make/paths.mk
kpse_include make/makevars.mk

# It's too bad we have to pass all these down, but I see no alternative,
# if we are to propagate changes at the top level.
# XMAKEARGS is for the user to override.
makeargs = $(MFLAGS) CC='$(CC)' CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS)' $(makevars) $(XMAKEARGS)
installargs = INSTALL_DATA='$(INSTALL_DATA)' \
  INSTALL_PROGRAM='$(INSTALL_PROGRAM)' $(makeargs)

# Not everything from common.mk is relevant to this top-level
# Makefile, but most of it is, and it doesn't seem worth separating the
# compilation-specific stuff.
kpse_include make/common.mk

# Get more of the default setup.
kpse_include make/programs.mk

# kpathsea is not a sibling, it's a child.
kpathsea_parent = .

# Make the library before the programs.
# Use if ... rather than || or && because Ultrix sh exits for
# no good reason with the latter.
default all: do-kpathsea
	for d in $(programs); do if test -f $$d/Makefile; then \
	  (cd $$d && $(MAKE) $(makeargs) $@) || exit 1; else true; fi; done

install install-data install-exec:
	for d in kpathsea $(programs); do if test -f $$d/Makefile; then \
	  (cd $$d && $(MAKE) $(installargs) $@) || exit 1; else true; fi; done

# Other standard targets for everything.
uninstall uninstall-exec uninstall-data \
mostlyclean clean realclean extraclean configclean \
info dvi check depend::
	for d in $(all_dirs); do if test -f $$d/Makefile; then \
	  (cd $$d && $(MAKE) $(makeargs) $@) || exit 1; else true; fi; done

distclean::
	rm -rf conftest*

distclean::
	for d in $(all_dirs); do if test -f $$d/Makefile; then \
	  (cd $$d && $(MAKE) $(makeargs) $@) || exit 1; else true; fi; done

distclean realclean::
	rm -f Makefile Makefile.aux config.status config.cache config.log libtool kpse_empty

# Unconditionally remake the library, since we don't want to write out
# the dependencies here.
do-kpathsea:
	cd $(kpathsea_dir) && $(MAKE) $(makeargs)

# Targets that only apply to web2c.
triptrap trip trap mptrap \
formats fmts bases mems \
install-formats install-fmts install-bases install-mems \
install-links c-sources: do-kpathsea
	cd web2c && $(MAKE) $(makeargs) $@

@MAINT@ac_dir = $(srcdir)/etc/autoconf
@MAINT@autoconf = $(ac_dir)/acspecific.m4 $(ac_dir)/acgeneral.m4 $(ac_dir)/acsite.m4
@MAINT@configure_in = $(srcdir)/configure.in
@MAINT@$(srcdir)/configure: $(configure_in) $(srcdir)/withenable.ac $(autoconf)
@MAINT@	cd $(srcdir) && $(srcdir)/autoconf2.13 -m $(ac_dir)
@MAINT@
@MAINT@# And make sure that --enable-maintainer-mode is used if configure is
@MAINT@# called from the makefiles.  We do not try to do this through the
@MAINT@# cache, lest the option sneaks into a global cache file.
@MAINT@enablemaintflag = --enable-maintainer-mode

config.status: $(srcdir)/configure
	$(SHELL) $(srcdir)/configure --no-create --verbose  $(enablemaintflag)

Makefile: $(srcdir)/Makefile.in config.status
	$(SHELL) config.status

TAGS:
	find $(srcdir) \( -name '*.[cCfFhilsy]' -o -name '*.el' \) | etags -
